import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView
    },
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue')
    },
    {
      path:'/pinia',
      component : ()=>import('@/components/TestPinia/TestPinia.vue')
    },
    {
      path:'/props',
      component : ()=>import('@/components/TestProps/FatherCom.vue')
    },
    {
      path:'/slot',
      component : ()=>import('@/components/TestSlot/FatherCom.vue')
    },
    {
      path: '/news',
      name: 'news',
      component: () => import('../views/NewsView.vue'),
      children: [
        {
          path: 'detail',
          name: 'detail',
          component: () => import('../views/DetailView.vue'),
          props: (route) => {
            return { id: route.query.id, title: route.query.title, content: route.query.content }
          }
        },
        {
          path: 'detail2/:id/:title/:content',
          name: 'detail2',
          component: () => import('../views/DetailView2.vue'),
          props: true
        },
        {
          path: 'detail3',
          name: 'detail3',
          component: () => import('../views/DetailView3.vue'),
          props: (route) => {
            return { id: route.query.id, title: route.query.title, content: route.query.content }
          }
        }
      ]
    }
  ]
})

export default router
